package org.chickymate.client.view.grid;

import java.util.List;

import org.chickymate.client.HtmlConstants;
import org.chickymate.client.model.ModelDTO;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

public abstract class AbstractModelGrid extends Composite {
	
	private FlowPanel panel;
	
	public AbstractModelGrid() {
		panel = new FlowPanel();
		panel.setStyleName(HtmlConstants.MODEL_DTO_CONTAINER_STYLE_NAME);
		initWidget(panel);
	}

	public void load(List<? extends ModelDTO> result) {
		clear();
		for(ModelDTO comment : result) {
			panel.add(createModelView(comment));
		}
	}
	
	private void clear() {
		panel.clear();
	}
	
	protected abstract Widget createModelView(ModelDTO model);

}
